-- Mousepull2

function love.load()
  
  rect = {
    x = 100,
    y = 200,
    width = 100,
    height = 100,
    move = { active = false, diffX = 0, diffY = 0, targetX = 0, targetY = 0}
  }
end

function love.update(dt)
if rect.move.diffX ~= 0 or rect.move.diffY ~= 0 then

	if rect.move.diffX ~= 0 then
		if rect.move.diffX > 0 then
			
			local i = 0
			while i ~= rect.move.diffX do
				--rect.x = rect.move.targetX
				rect.x = rect.move.diffX
				--rect.y = rect.move.targetY
				rect.move.diffX = rect.move.diffX - 1
				--love.timer.sleep(1)
			end
		elseif rect.move.diffX < 0 then
			local i = 0
			while i ~= rect.move.diffX do
				--rect.x = rect.move.targetX
				rect.x = rect.move.diffX
				--rect.y = rect.move.targetY
				rect.move.diffX = rect.move.diffX + 1
				--love.timer.sleep(1)
			end
		end
		
	end
	
	if rect.move.diffY ~= 0 then
		if rect.move.diffY > 0 then
			
			local i = 0
			while i ~= rect.move.diffY do
				--rect.x = rect.move.targetX
				rect.y = rect.move.diffY
				--rect.y = rect.move.targetY
				rect.move.diffY = rect.move.diffY - 1
				--love.timer.sleep(1)
			end
		elseif rect.move.diffY < 0 then
			local i = 0
			while i ~= rect.move.diffY do
				--rect.x = rect.move.targetX
				rect.y = rect.move.diffY
				--rect.y = rect.move.targetY
				rect.move.diffY = rect.move.diffY + 1
				--love.timer.sleep(1)
			end
		end
		
	end
	
end
end

function love.draw()
local e, f = love.mouse.getPosition()
--love.graphics.print("The mouse is at (" .. e .. "," .. f .. ")", 50, 50)
  love.graphics.print("The box is at (" .. rect.x .. "," .. rect.y .. ")", 100, 100)
  love.graphics.rectangle("fill", rect.x, rect.y, rect.width, rect.height)
  love.graphics.print("Diffs are (" .. rect.move.diffX .. "," .. rect.move.diffY .. ")", 100, 140)
  love.graphics.print("Targets are (" .. rect.move.targetX .. "," .. rect.move.targetY .. ")", 100, 160)
end

function love.mousepressed(x, y, button)
  if button == "l" -- if left button is pressed
  
  then
    rect.move.active = true
	rect.move.diffX = x - rect.x
	rect.move.diffY = y - rect.y
    rect.move.targetX = x
    rect.move.targetY = y
	-- diff, math current position vs target position.
  end
  
end

function love.mousereleased(x, y, button)
  if button == "l" then rect.move.active = false end
end